#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;

int gcd(int a, int b)
{
    return b ? gcd(b, a % b) : a;
}

ll qmi(ll a, ll b)
{
    ll res = 1;
    while(b)
    {
        res = res * a % mod;
        b >>= 1;
        a = a * a % mod;
    }
    return res;
}

void solve()
{
    int n, m;
    cin >> n >> m;
    string s;
    cin >> s;
    vector<int>a(m);
    for(int i = 0; i < m; i++) cin >> a[i];
    string c;
    cin >> c;
    cout << c << endl;
    sort(c.begin(), c.end());
    // cout << c << endl;
    sort(a.begin(), a.end());
    vector<bool>st(n);
    int j = 0;
    for(int i = 0; i < m; i++)
    {
        if(!st[a[i] - 1])
        {
            s[a[i] - 1] = c[j++];
            st[a[i] - 1] = true;
        }
    }
    cout << s << endl;
}

int main()
{
    int t;
    cin >> t;
    while(t--) solve();
    return 0;
}